package com.itheima.service.impl;

import com.itheima.mapper.UserMapper;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @className UserServiceImpl
 */
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;

    /**
     * 根据用户名查询用户信息
     * @param username
     * @return User
     **/
    public User selectUserByUsername(String username) {
        return Optional.ofNullable(userMapper.selectUserByUsername(username))
                .orElse(null);
    }

    /**
     * 根据用户id查询角色信息
     * @param id
     * @return List<Role>
     **/
    public List<Role> selectRolesByUserId(Integer id) {
        return Optional.ofNullable(userMapper.selectRolesByUserId(id))
                .orElse(null);
    }
}
